<script setup>
import { ref,reactive, nextTick,onActivated,getCurrentInstance,onMounted, watch  } from 'vue'; 
import { useRoute,useRouter } from 'vue-router';
import { ElMessage,ElMessageBox  } from 'element-plus';
import { newArea } from "@/utils/area.js";
const seachTable = ref(null);
const route = useRoute();
const router = useRouter();
const instance = getCurrentInstance();
const selectionAll = ref([])
// 选择选项的更改
const handleSelectionChange = (val) => {
   console.log(val,'val');
   selectionAll.value = val
}
// 新增编辑回退时候刷新列表
onActivated(()=>{
    let closeTagName = sessionStorage.getItem('closeTagName');
    console.log(closeTagName,'closeTagName');
    if(closeTagName == 'pharmacistManageEdit'){
        seachTable.value.handlerSearch();
        
    }else if(closeTagName == 'pharmacistManageAdd'){
        seachTable.value.initSearch();
    }
    instance.proxy.$forceUpdate();
    sessionStorage.removeItem('closeTagName');
})


// 跳转到门店逻辑
const goDoorManege = () => {
  console.log('llllll');
}
const formInline = ref([
    {
      type: "datePicker",
      prop: ["startTime", "endTime"],
      startPlaceholder: "创建开始时间",
      endPlaceholder: "创建结束时间",
      label: "",
      model: [],
    },
    {
      type: "input",
      prop: "name",
      placeholder: "商户名称/ID",
      label: "",
      model: "",
    },
    {
        type: "select",
        placeholder: "商户分组",
        label: '',
        multiple:true,
        prop: 'type',
        data:[
            {
                label:"审方",
                value:1
            },
            {
                label:"咨询",
                value:2
            }
        ],
        model: [1]
    },
    {
        type: "select",
        placeholder: "经营方式",
        label: '',
        prop: 'type',
        data:[
            {
                label:"直营",
                value:2
            },
            {
              
                label:"加盟",
                value:1
            }
        ],
        model: [],
    },
])

const btnLefts = ref([
    {
        label:"批量上架",
        plain:true,
        type:"primary",
        show:true,
        // img:new URL("@/assets/icon/btn-add.png",import.meta.url),
        click:async ()=>{
            // router.push({name:"merchantChildManageAdd"})
        }
    },
    {
        label:"批量下架",
        plain:true,
        type:"danger",
        show:true,
        // img:new URL("@/assets/icon/btn-add.png",import.meta.url),
        click:async ()=>{
            // router.push({name:"merchantChildManageAdd"})
        }
    }

])
const btnRights = ref([
    // {
    //     label:"导出",
    //     plain:false,
    //     plain:true,
    //     show:true,
    //     img:new URL("@/assets/icon/btn-export.png",import.meta.url),
    //     style:"border-color:#0C268C;color:#0C268C",
    //     click:async ()=>{

    //     }
    // }
])

const tableConfig = ref([
    {
      type:'slot',
      slotName:'goodsSlot',
      prop: "goods",
      label: "商品",
      width:570
    },
    {
      prop: "name",
      label: "库存",
      sortable:true,
      // width:72
    },
    {
      prop: "mobile",
      label: "参考批发价",
      sortable:true,
      // width:114
    },
    {
      prop: "type",
      label: "分类",
      // width:120
    },
    {
      prop: "institutions",
      label: "状态",
      // width:200
    },
    {
      type: "action",
      label: "操作",
      width: 100,
      btns: [
          {
            label: () => "上架",
            type:"primary",
            show:(row)=>{
              return row.state == 1 && row.source == 3;
            },
            click: async (row) => {
              ElMessageBox(
                  {
                      confirmButtonText: '确定',
                      cancelButtonText: '取消',
                      type: 'warning',
                      title: '提示',
                      showCancelButton: true,
                      message:"是否上架该商品?",
                      beforeClose: async (action, instance, done) => {
                          if (action === 'confirm') {
                              instance.confirmButtonLoading = true
                              instance.confirmButtonText = 'Loading...'
                              ElMessage.success('上架成功');
                              seachTable.value.handlerSearch();
                          } else {
                              done()
                          }
                      },
                  }
              )
            },
          },
        //  {
        //   label: () => "下架",
        //   type:"danger",
        //   show:(row)=>{
        //     return row.state == 1 && row.source == 3;
        //   },
        //   click: async (row) => {
        //     ElMessageBox(
        //         {
        //             confirmButtonText: '确定',
        //             cancelButtonText: '取消',
        //             type: 'warning',
        //             title: '禁用',
        //             showCancelButton: true,
        //             confirmButtonClass: 'delete',
        //             message:"是否下架该商品?",
        //             beforeClose: async (action, instance, done) => {
        //                 if (action === 'confirm') {
        //                     instance.confirmButtonLoading = true
        //                     instance.confirmButtonText = 'Loading...'
        //                     ElMessage.success('下架成功');
        //                     seachTable.value.handlerSearch();
        //                 } else {
        //                     done()
        //                 }
        //             },
        //         }
        //     )
        //   },
        // },
      ],
    },
]);
const tableLoading = ref(false)
const totalPage = ref(0)
const tableData = ref([]);


const handlerSearch = async (formInline)=>{
    tableLoading.value = true;
    try{
        
        totalPage.value = 100;
        tableData.value = [
            {
                "doctorNumberCode": "YS000299",
                "type": "审方",
                "name": "12313",
                "mobile": "18207123212",
                "idCard": "",
                "frontUrl": "https://static.91medicine.net/images/20230919/2930e77d-fba7-4a7e-bbc4-f6815eca5a6d.jpg",
                "headUrl": "https://static.91medicine.net/images/20230919/f6159f8e-c44a-43cc-ae5c-3ddfc659cd7a.jpg",
                "introduce": "3123",
                "institutions": "九为（浙江）网络科技有限公司",
                "certificateUrl": "https://static.91medicine.net/images/20230919/d5e597c3-1c76-4646-a843-03b0b8686a03.jpg",
                "certificateNo": "312312",
                "titleValue": "",
                "uuid": "8a69c4628aab7785018aac0eb31f0004",
                "state": 1,
                "sfdaDoctorType": "1",
                "storeLocationUuid": "",
                "source": "3"
            },
            {
                "doctorNumberCode": "YS000298",
                "type": "审方",
                "name": "63443",
                "mobile": "18205859721",
                "idCard": "1231",
                "frontUrl": "https://static.91medicine.net/images/20230919/a17280e1-702b-4489-97b5-91aed2b7e8ce.jpg",
                "headUrl": "https://static.91medicine.net/images/20230919/c5977a4f-feaf-4bc0-aaff-b61c88a13154.jpg",
                "introduce": "31231",
                "institutions": "九为（浙江）网络科技有限公司",
                "certificateUrl": "https://static.91medicine.net/images/20230919/8564c2ed-3df7-41c2-b8ad-e41b79367ca6.jpg",
                "certificateNo": "312312",
                "titleValue": "",
                "uuid": "8a69c4628aab7785018aac0a6a070000",
                "state": 1,
                "sfdaDoctorType": "1",
                "storeLocationUuid": "",
                "source": "3"
            },
            {
                "doctorNumberCode": "YS000297",
                "type": "咨询",
                "name": "谢362",
                "mobile": "18042518903",
                "idCard": "511024199911211291",
                "frontUrl": "https://static.91medicine.net/images/20230906/69c03021-0a22-4f7d-98a0-b7ec15733e4b.jpg",
                "headUrl": "https://static.91medicine.net/images/20230906/91ef9b58-9fb6-4adb-a964-6311c9d53ba3.jpg",
                "introduce": "",
                "institutions": "宁波市镇海华美星辰健康大药房有限公司",
                "certificateUrl": "https://static.91medicine.net/images/20230906/2e1ecf44-8607-4945-87b1-20dbe25eca50.jpg",
                "certificateNo": "201291",
                "titleValue": "",
                "uuid": "8a69c3d18a4f762d018a683d280c000c",
                "state": 1,
                "sfdaDoctorType": "2",
                "storeLocationUuid": "71345f78c1e4da48e4edc5347df4d2e7",
                "source": "3"
            },
            {
                "doctorNumberCode": "YS000296",
                "type": "咨询,审方",
                "name": "测试机2",
                "mobile": "18069132578",
                "idCard": "420101197701283253",
                "frontUrl": "https://static.91medicine.net/images/20230905/f58659b8-8e02-44ab-b419-59f673c01571.png",
                "headUrl": "https://static.91medicine.net/images/20230905/1a3a3e72-baf7-40f9-a8d9-19bafe3e0abf.png",
                "introduce": "",
                "institutions": "九为（浙江）网络科技有限公司",
                "certificateUrl": "https://static.91medicine.net/images/20230905/07a53eab-2b04-4898-b99b-6e4dbcdc70e3.png",
                "certificateNo": "353453",
                "titleValue": "",
                "uuid": "8a69c3d18a4f762d018a645176630007",
                "state": 1,
                "sfdaDoctorType": "1",
                "storeLocationUuid": "",
                "source": "3"
            },
            {
                "doctorNumberCode": "YS000295",
                "type": "咨询",
                "name": "储伟军",
                "mobile": "13957418736",
                "idCard": "330226197710216395",
                "frontUrl": "https://static.91medicine.net/images/20230831/78d8e1cc-d522-4568-bceb-6ecdee85df10.jpg",
                "headUrl": "https://static.91medicine.net/images/20230831/089aa8f3-ff87-4d1d-8a1a-4feca7497638.jpg",
                "introduce": "",
                "institutions": "九为（浙江）网络科技有限公司",
                "certificateUrl": "https://static.91medicine.net/images/20230831/05fa293d-2a38-436f-8e4d-51250b0731ce.jpg",
                "certificateNo": "330207",
                "titleValue": "",
                "uuid": "8a69c3518a406975018a493e38740006",
                "state": 1,
                "sfdaDoctorType": "1",
                "storeLocationUuid": "",
                "source": "3"
            },
            {
                "doctorNumberCode": "YS000294",
                "type": "咨询",
                "name": "陈",
                "mobile": "15717031390",
                "idCard": "362330197809092019",
                "frontUrl": "https://static.91medicine.net/images/20230829/9340326e-5445-4e8c-976f-86f0ecc9b038.jpeg",
                "headUrl": "https://static.91medicine.net/images/20230829/c1e5a62d-92c3-494c-ba7f-f785f8aa4d6f.jpg",
                "introduce": "...",
                "institutions": "宁波市镇海福兴大药房",
                "certificateUrl": "https://static.91medicine.net/images/20230829/3bffc669-cd51-483c-8d7b-d317611e07dd.jpeg",
                "certificateNo": "211321",
                "titleValue": "",
                "uuid": "8a69c3518a406975018a407ecc250001",
                "state": 1,
                "sfdaDoctorType": "2",
                "storeLocationUuid": "a05146b4a2b1c6bc684d245b98e96511",
                "source": "3"
            },
            {
                "doctorNumberCode": "YS000293",
                "type": "咨询",
                "name": "叶叶",
                "mobile": "15167049206",
                "idCard": "362330197808082011",
                "frontUrl": "https://static.91medicine.net/images/20230825/80099690-2ed3-41ab-b910-6021f19e0556.jpeg",
                "headUrl": "https://static.91medicine.net/images/20230825/5c70356a-4288-4bd2-a1f9-2c8d48ac5cdc.jpeg",
                "introduce": "8年药师执业经验,职业与镇海一心辰大药房",
                "institutions": "宁波市镇海诚普大药房",
                "certificateUrl": "https://static.91medicine.net/images/20230825/344e9e1d-0504-41ef-b126-36b02fd4a1e8.jpeg",
                "certificateNo": "665544",
                "titleValue": "",
                "uuid": "8a69c46c8a214525018a2bba237d0000",
                "state": 1,
                "sfdaDoctorType": "2",
                "storeLocationUuid": "998029f98812d5506d57299f4e049420",
                "source": "3"
            },
            {
                "doctorNumberCode": "YS000292",
                "type": "咨询",
                "name": "傅俊杰",
                "mobile": "15257492356",
                "idCard": "330821199711081410",
                "frontUrl": "https://static.91medicine.net/images/20230810/37a6ac25-077d-4c82-b644-3088f1acaf39.jpg",
                "headUrl": "https://static.91medicine.net/images/20230810/081575f3-08f2-4967-869a-bf9322c6d049.png",
                "introduce": "从业 8 年经验",
                "institutions": "宁波市镇海诚普大药房",
                "certificateUrl": "https://static.91medicine.net/images/20230810/b02c3f58-f0a3-4664-b42c-13a8c2c4d62a.jpg",
                "certificateNo": "011231",
                "titleValue": "",
                "uuid": "8a69c3d989d95be30189dd6463c0000d",
                "state": 1,
                "sfdaDoctorType": "2",
                "storeLocationUuid": "998029f98812d5506d57299f4e049420",
                "source": "3"
            },
            {
                "doctorNumberCode": "YS000291",
                "type": "咨询",
                "name": "马秀卿",
                "mobile": "18758550852",
                "idCard": "330724199412136921",
                "frontUrl": "https://static.91medicine.net/images/20230810/80cad9b3-1d39-4ecf-928d-1c18226c378f.jpg",
                "headUrl": "https://static.91medicine.net/images/20230810/e43aa1ae-3344-40be-8ca0-8b594d9261b8.png",
                "introduce": "从业 12 年经验",
                "institutions": "九为（浙江）网络科技有限公司",
                "certificateUrl": "https://static.91medicine.net/images/20230810/eefe94f2-cc38-4747-8619-0d9b3f992ecc.jpg",
                "certificateNo": "205148",
                "titleValue": "",
                "uuid": "8a69c3d989d95be30189dd29ba3c0000",
                "state": 1,
                "sfdaDoctorType": "1",
                "storeLocationUuid": "8a69c3d989d95be30189dd29bb330002",
                "source": "3"
            },
            {
                "doctorNumberCode": "YS000289",
                "type": "咨询",
                "name": "柯洁",
                "mobile": "15168245310",
                "idCard": "110101200203079198",
                "frontUrl": "https://static.91medicine.net/images/20230718/923b9a39-e95a-4aa7-8c12-2d93645886fa.png",
                "headUrl": "https://static.91medicine.net/images/20230718/3c5bea36-347a-4def-8b7c-17353dcb3470.png",
                "introduce": "从事骨科临床、科研工作40余年",
                "institutions": "大剧院",
                "certificateUrl": "https://static.91medicine.net/images/20230718/a407179b-6eb2-468a-a2bc-0e3068ed9af9.png",
                "certificateNo": "100861",
                "titleValue": "",
                "uuid": "8a69c44e89617fe9018966ca88eb000e",
                "state": 1,
                "sfdaDoctorType": "1",
                "storeLocationUuid": "8a69c44e89617fe9018966ca895a0010",
                "source": "3"
            }
        ];
        tableLoading.value = false;
    }catch(e){
        tableLoading.value = false;
    }
}



</script>
<template>
    <div class="page-content">
        <SeachTable 
          :tableType="1"
          ref="seachTable"
          :forms="formInline"
          :btnLefts="btnLefts"
          :btnRights="btnRights"
          :tableLoading="tableLoading"
          :tableConfig="tableConfig"
          :tableData="tableData"
          :totalPage="totalPage"
          :tableSelection="true" 
          @handleSelectionChange="handleSelectionChange"
          @handlerSearch="handlerSearch"
        >
        <template #goodsSlot="{row}">
          <div class="doods-slot">
            <div class="img-pic">
              <el-image
                  style="width: 100%; height: 100%"
                  :src="'https://static.91medicine.net/images/20230919/c5977a4f-feaf-4bc0-aaff-b61c88a13154.jpg'"
                  fit="cover"
                  :preview-src-list="['https://static.91medicine.net/images/20230919/c5977a4f-feaf-4bc0-aaff-b61c88a13154.jpg']"
                />
            </div>
            <div class="text-view">
                <div class="top-title">
                  ask决定恢复老师电话发卡机士大夫看见哈桑说的话饭卡手动阀哈师大ask的话饭卡上的
                </div>
                <div class="spec-title">
                  15ml*6瓶
                </div>
            </div>
          </div>
        </template>
        </SeachTable>
    </div>
</template>


<style lang="less" scoped>
  .doods-slot{
    display: flex;
    align-items: center;
    width: 100%;
      .img-pic{
        width: 48px;
        height:48px;
      }
      .text-view{
        margin-left: 8px;
        .top-title{
          margin-bottom:8px;
          width: 482px;
          overflow: hidden;
          text-overflow:ellipsis;
          white-space: nowrap;
          color: #3480ff;
          font-family: "PingFang SC";
          font-size: 14px;
          font-style: normal;
          font-weight: 500;
          line-height: 14px;
        }
        .spec-title{
          color: #666666;
          font-family: "PingFang SC";
          font-size: 14px;
          font-style: normal;
          font-weight: 400;
          line-height: 14px;
        }
      }
  }
</style>


<!-- 删除按钮样式 -->
<style lang="less">
.delete{
    background: #FF2440 !important;
}
</style>